package com.javasm.mb_store_api_final.giftsandgoods.goodsType.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javasm.common.R;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.entity.GgGoodsType;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.service.GgGoodsTypeService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.vo.TypeBrandVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.vo.TypeVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.vo.TypeidVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lh
 * @version 0.1
 * @className GoodsTypeController
 * @date 2024/8/2 19:58
 * @description
 * @since jdk11
 */
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Resource
    GgGoodsTypeService typeService;

    @PostMapping("/list")
    public R goodsTypeList(@RequestBody TypeVo typeVo){
        IPage<GgGoodsType> page = typeService.listByTypeName(typeVo);
        return R.ok(page);
    }
    //添加商品类型
    @PostMapping("/addType")
    public R addType(@RequestBody GgGoodsType type){
        boolean b = typeService.save(type);
        return R.ok(b);
    }
    //删除商品类型
    @PostMapping("/deleteType")
    public R deleteType(@RequestBody GgGoodsType type){
        boolean b = typeService.removeById(type.getId());
        return R.ok(b);
    }
    //根据id修改商品类型
    @PostMapping("/updateType")
    public R updateType(@RequestBody GgGoodsType type){
        boolean b = typeService.updateById(type);
        return R.ok(b);
    }
    //根据id查询商品类型
    @PostMapping("/getById")
    public R getById(@RequestBody TypeidVo id){
        GgGoodsType byId = typeService.getById(id.getId());
        return R.ok(byId);
    }
    //前端传来json字符串{rowId: '10', checkList: Array(5)},
    @PostMapping("/updateBrandNameById")
    public R insertBrandNameById(@RequestBody TypeBrandVo typeBrandVo){
        boolean b = typeService.insertBrandNameById(typeBrandVo);
        return R.ok(b);
    }

}
